package org.jeecg.modules.tls.csmg.cscourse.service.impl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.tls.blog.blogarticletag.entity.BlogArticleTag;
import org.jeecg.modules.tls.blog.common.ResponseResult;
import org.jeecg.modules.tls.csmg.cschapter.entity.CsChapter;
import org.jeecg.modules.tls.csmg.cschapter.mapper.CsChapterMapper;
import org.jeecg.modules.tls.csmg.cscourse.entity.CsCourse;
import org.jeecg.modules.tls.csmg.cscourse.mapper.CsCourseMapper;
import org.jeecg.modules.tls.csmg.cscourse.service.ICsCourseService;
import org.jeecg.modules.tls.csmg.cssection.entity.CsSection;
import org.jeecg.modules.tls.csmg.cssection.mapper.CsSectionMapper;
import org.jeecg.modules.tls.csmg.cssection.service.ICsSectionService;
import org.jeecg.modules.tls.csmg.csvideoscript.entity.CsVideoScript;
import org.jeecg.modules.tls.csmg.csvideoscript.mapper.CsVideoScriptMapper;
import org.jeecg.modules.tls.csmg.viewmodel.admin.*;
import org.jeecg.modules.tls.csmg.viewmodel.user.*;
import org.jeecg.modules.tls.oes.subject.entity.OesSubject;
import org.jeecg.modules.tls.oes.subject.mapper.OesSubjectMapper;
import org.jeecg.modules.user.entity.SysUserDemo;
import org.jeecg.modules.user.mapper.SysUserDemoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: cs_course
 * @Author: jeecg-boot
 * @Date:   2022-08-05
 * @Version: V1.0
 */
@Service
public class CsCourseServiceImpl extends ServiceImpl<CsCourseMapper, CsCourse> implements ICsCourseService {
    @Autowired
    CsCourseMapper csCourseMapper;
    @Autowired
    CsChapterMapper csChapterMapper;
    @Autowired
    ICsSectionService iCsSectionService;
    @Autowired
    CsSectionMapper csSectionMapper;
    @Autowired
    OesSubjectMapper oesSubjectMapperl;
    @Autowired
    SysUserDemoMapper sysUserDemoMapper;
    @Autowired
    CsVideoScriptMapper csVideoScriptMapper;
    @Override
    public Boolean addCourse(CourseRequestVM courseRequestVM) {
        //转json
        JSONArray arraySorts = new JSONArray();
        arraySorts.addAll(courseRequestVM.getSorts());
        //转json
        JSONArray arrayprincipal = new JSONArray();
        arrayprincipal.addAll(courseRequestVM.getPersonInCharge());
        //设置课程信息
        CsCourse csCourse = new CsCourse();
        csCourse.setName(courseRequestVM.getName());
        csCourse.setCover(courseRequestVM.getCover());
        csCourse.setSorts(arraySorts.toString());
        csCourse.setIntegral(courseRequestVM.getIntegral());
        csCourse.setIntroduction(courseRequestVM.getIntroduction());
        csCourse.setLecturer(courseRequestVM.getLecturer());
        csCourse.setPersonInCharge(arrayprincipal.toString());
        csCourse.setLevel(courseRequestVM.getLevel());
        csCourse.setVideoPlaybackTimes(0);
        //通过id是否为null判断是新增还是编辑
        if(courseRequestVM.getId()==null||courseRequestVM.getId().equals("null")){
            csCourse.setCreateUser(courseRequestVM.getCreateUser());
            csCourseMapper.insert(csCourse);
            //插入章节
            courseRequestVM.getChapterRequestVMList().stream().forEach(i->{
                CsChapter csChapter = new CsChapter();
                csChapter.setCourseId(csCourse.getId());
                csChapter.setName(i.getName());
                csChapter.setCreateUser(courseRequestVM.getCreateUser());
                csChapterMapper.insert(csChapter);
                //插入小节
                i.getCsSectionList().stream().forEach(j->{
                    CsSection csSection = new CsSection();
                    csSection.setName(j.getName());
                    csSection.setClassify(j.getClassify());
                    csSection.setContent(j.getContent());
                    csSection.setDocumentPath(j.getDocumentPath());
                    csSection.setRequiredStudyTime(j.getRequiredStudyTime());
                    csSection.setChapterId(csChapter.getId());
                    csSection.setCreateUser(courseRequestVM.getCreateUser());
                    if(j.getClassify()==1){
                        csSection.setVideoDuration(j.getVideoDuration());
                    }
                    iCsSectionService.save(csSection);
                    //如果分类为视频且视频脚本不为null，则插入视频脚本
                    if(j.getClassify()==1&&j.getVideoScriptItems().size()>0){
                        j.getVideoScriptItems().stream().forEach(k->{
                            CsVideoScript csVideoScript = new CsVideoScript();
                            csVideoScript.setSectionId(csSection.getId());
                            csVideoScript.setTitle(k.getTitle());
                            csVideoScript.setNumberOfSeconds(k.getNumberOfSeconds());
                            csVideoScript.setModel(k.getModel());
                            if(k.getModel()==1){
                                JSONArray optionsJsonArray = JSONUtil.parseArray(k.getOptions());
                                csVideoScript.setOptionInformation(optionsJsonArray.toString());
                            }else {
                                csVideoScript.setContent(k.getContent());
                            }
                            csVideoScriptMapper.insert(csVideoScript);
                        });
                    }
                });
            });
             return true;
        }else {
            csCourse.setId(courseRequestVM.getId());
            csCourseMapper.updateById(csCourse);

            //先查出来当前课程有哪些章节id
            QueryWrapper<CsChapter> chapterQueryWrapper = new QueryWrapper<>();
            chapterQueryWrapper.eq("course_id",courseRequestVM.getId());
            List<CsChapter> csChapterList = csChapterMapper.selectList(chapterQueryWrapper);
            List<String> chapterIdList = csChapterList.stream().map(CsChapter::getId).collect(Collectors.toList());
            courseRequestVM.getChapterRequestVMList().stream().forEach(i->{
                CsChapter csChapter = new CsChapter();
                //判断这个章节时修改还是新增的
                if(chapterIdList.contains(i.getId())){
                    chapterIdList.remove(i.getId());
                    csChapter.setName(i.getName());
                    csChapter.setId(i.getId());
                    csChapterMapper.updateById(csChapter);

                    //获取当前章节下的小节id
                    QueryWrapper<CsSection> sectionQueryWrapper = new QueryWrapper<>();
                    sectionQueryWrapper.eq("chapter_id",i.getId());
                    List<CsSection> csSectionList = csSectionMapper.selectList(sectionQueryWrapper);
                    List<String> sectionIdList = csSectionList.stream().map(CsSection::getId).collect(Collectors.toList());
                    i.getCsSectionList().stream().forEach(j->{
                        CsSection csSection = new CsSection();
                        csSection.setName(j.getName());
                        csSection.setClassify(j.getClassify());
                        csSection.setContent(j.getContent());
                        csSection.setDocumentPath(j.getDocumentPath());
                        csSection.setRequiredStudyTime(j.getRequiredStudyTime());
                        if(j.getClassify()==1){
                            csSection.setVideoDuration(j.getVideoDuration());
                        }
                        //判断这个小节是新增还是编辑
                        if(sectionIdList.contains(j.getId())){
                            sectionIdList.remove(j.getId());
                            csSection.setId(j.getId());
                            iCsSectionService.updateById(csSection);

                            //获取当前小节下的视频脚本id集合
                            QueryWrapper<CsVideoScript> videoScriptQueryWrapper = new QueryWrapper<>();
                            videoScriptQueryWrapper.eq("section_id",j.getId());
                            List<CsVideoScript> videoScriptList = csVideoScriptMapper.selectList(videoScriptQueryWrapper);
                            List<String> videoScriptIdList = videoScriptList.stream().map(CsVideoScript::getId).collect(Collectors.toList());
                            //如果分类为视频且视频脚本不为null，则插入视频脚本
                            if(j.getClassify()==1&&j.getVideoScriptItems().size()>0){
                                j.getVideoScriptItems().stream().forEach(k->{
                                    CsVideoScript csVideoScript = new CsVideoScript();
                                    csVideoScript.setTitle(k.getTitle());
                                    csVideoScript.setNumberOfSeconds(k.getNumberOfSeconds());
                                    csVideoScript.setModel(k.getModel());

                                    //判断当前视频脚本是新增还是编辑
                                    if(videoScriptIdList.contains(k.getId())){
                                        videoScriptIdList.remove(k.getId());
                                        csVideoScript.setId(k.getId());
                                        if(k.getModel()==1){
                                            JSONArray optionsJsonArray = JSONUtil.parseArray(k.getOptions());
                                            csVideoScript.setOptionInformation(optionsJsonArray.toString());
                                            csVideoScript.setContent(null);
                                        }else {
                                            csVideoScript.setContent(k.getContent());
                                            csVideoScript.setOptionInformation(null);
                                        }
                                        csVideoScriptMapper.updateById(csVideoScript);
                                    }else {
                                        if(k.getModel()==1){
                                            JSONArray optionsJsonArray = JSONUtil.parseArray(k.getOptions());
                                            csVideoScript.setOptionInformation(optionsJsonArray.toString());
                                        }else {
                                            csVideoScript.setContent(k.getContent());
                                        }
                                        csVideoScript.setSectionId(csSection.getId());
                                        csVideoScriptMapper.insert(csVideoScript);
                                    }
                                });
                            }
                            //删除被删除的脚本
                            videoScriptIdList.stream().forEach(id->csVideoScriptMapper.deleteById(id));


                        }else {
                            csSection.setChapterId(csChapter.getId());
                            csSection.setCreateUser(courseRequestVM.getCreateUser());
                            iCsSectionService.save(csSection);
                            //如果分类为视频且视频脚本不为null，则插入视频脚本
                            if(j.getVideoScriptItems()!=null&&(j.getClassify()==1&&j.getVideoScriptItems().size()>0)){
                                j.getVideoScriptItems().stream().forEach(k->{
                                    CsVideoScript csVideoScript = new CsVideoScript();
                                    csVideoScript.setSectionId(csSection.getId());
                                    csVideoScript.setTitle(k.getTitle());
                                    csVideoScript.setNumberOfSeconds(k.getNumberOfSeconds());
                                    csVideoScript.setModel(k.getModel());
                                    if(k.getModel()==1){
                                        JSONArray optionsJsonArray = JSONUtil.parseArray(k.getOptions());
                                        csVideoScript.setOptionInformation(optionsJsonArray.toString());
                                    }else {
                                        csVideoScript.setContent(k.getContent());
                                    }
                                    csVideoScriptMapper.insert(csVideoScript);
                                });
                            }
                        }
                    });
                    sectionIdList.stream().forEach(ids-> iCsSectionService.removeById(ids));

                }else {
                    csChapter.setCourseId(csCourse.getId());
                    csChapter.setName(i.getName());
                    csChapter.setCreateUser(courseRequestVM.getCreateUser());
                    csChapterMapper.insert(csChapter);
                    //插入小节
                    i.getCsSectionList().stream().forEach(j->{
                        CsSection csSection = new CsSection();
                        csSection.setName(j.getName());
                        csSection.setClassify(j.getClassify());
                        csSection.setContent(j.getContent());
                        csSection.setDocumentPath(j.getDocumentPath());
                        csSection.setRequiredStudyTime(j.getRequiredStudyTime());
                        csSection.setChapterId(csChapter.getId());
                        csSection.setCreateUser(courseRequestVM.getCreateUser());
                        if(j.getClassify()==1){
                            csSection.setVideoDuration(j.getVideoDuration());
                        }
                        iCsSectionService.save(csSection);
                        //如果分类为视频且视频脚本不为null，则插入视频脚本
                        if(j.getVideoScriptItems()!=null&&(j.getClassify()==1&&j.getVideoScriptItems().size()>0)){
                            j.getVideoScriptItems().stream().forEach(k->{
                                CsVideoScript csVideoScript = new CsVideoScript();
                                csVideoScript.setSectionId(csSection.getId());
                                csVideoScript.setTitle(k.getTitle());
                                csVideoScript.setNumberOfSeconds(k.getNumberOfSeconds());
                                csVideoScript.setModel(k.getModel());
                                if(k.getModel()==1){
                                    JSONArray optionsJsonArray = JSONUtil.parseArray(k.getOptions());
                                    csVideoScript.setOptionInformation(optionsJsonArray.toString());
                                }else {
                                    csVideoScript.setContent(k.getContent());
                                }
                                csVideoScriptMapper.insert(csVideoScript);
                            });
                        }
                    });
                }
            });

            chapterIdList.stream().forEach(id->csChapterMapper.deleteById(id));
            return true;
        }

    }

    @Override
    public CourseRequestVM getCourse(String id) {
        //查询课程信息
        CsCourse csCourse = csCourseMapper.selectById(id);
        //解析json
        JSONArray arraySorts = JSONUtil.parseArray(csCourse.getSorts());
        List<Integer> sortsItems = JSONUtil.toList(arraySorts,Integer.class);
        //获取科目分类集合
        List<String> sortsNames = sortsItems.stream().map(i->{
            OesSubject oesSubject = oesSubjectMapperl.selectById(i);

            return oesSubject.getName();
        }).collect(Collectors.toList());
        //解析负责人json
        JSONArray arrayPrincipal = JSONUtil.parseArray(csCourse.getPersonInCharge());
        List<String> principalItems = JSONUtil.toList(arrayPrincipal,String.class);


        //获取负责人名集合
        List<String> arrayPrincipalNames = principalItems.stream().map(i->{
            SysUserDemo sysUserDemo = sysUserDemoMapper.selectById(i);
            return sysUserDemo.getRealname();
        }).collect(Collectors.toList());
        //查询章节信息
        QueryWrapper<CsChapter> csChapterQueryWrapper = new QueryWrapper<>();
        csChapterQueryWrapper.eq("course_id",id);
        List<CsChapter> csChapterList = csChapterMapper.selectList(csChapterQueryWrapper);

        //设置值并查询对应的小节信息
        List<ChapterRequestVM> chapterRequestVMList = csChapterList.stream().map(i->{
            ChapterRequestVM chapterRequestVM = new ChapterRequestVM();
            chapterRequestVM.setId(i.getId());
            chapterRequestVM.setName(i.getName());
            QueryWrapper<CsSection> csSectionQueryWrapper = new QueryWrapper<>();
            csSectionQueryWrapper.eq("chapter_id",i.getId());

            List<CsSection> csSectionList = csSectionMapper.selectList(csSectionQueryWrapper);
            //设置小节信息
            List<SectionRequestVM> sectionRequestVMLists = csSectionList.stream().map(j->{
                SectionRequestVM sectionRequestVM = new SectionRequestVM();
                QueryWrapper<CsVideoScript> videoScriptQueryWrapper = new QueryWrapper<>();
                videoScriptQueryWrapper.eq("section_id",j.getId());
                List<CsVideoScript> csVideoScriptList = csVideoScriptMapper.selectList(videoScriptQueryWrapper);
                //视频脚本数据
                List<VideoScriptRequestVM> videoScriptRequestVMList = csVideoScriptList.stream().map(k->{
                    VideoScriptRequestVM videoScriptRequestVM = new VideoScriptRequestVM();
                    videoScriptRequestVM.setId(k.getId());
                    videoScriptRequestVM.setModel(k.getModel());
                    videoScriptRequestVM.setTitle(k.getTitle());
                    videoScriptRequestVM.setNumberOfSeconds(k.getNumberOfSeconds());
                    if(k.getModel()==1){
                        JSONArray array = JSONUtil.parseArray(k.getOptionInformation());
                        List<VideoScriptOptionRequestVM> videoScriptOptionRequestVMList = JSONUtil.toList(array, VideoScriptOptionRequestVM.class);
                        videoScriptRequestVM.setOptions(videoScriptOptionRequestVMList);
                    }else {
                        String defaultOptionInformation = "[{\"prefix\":\"A\",\"content\":null,\"jump\":"+k.getNumberOfSeconds()+"},{\"prefix\":\"B\",\"content\":null,\"jump\":"+k.getNumberOfSeconds()+"},{\"prefix\":\"C\",\"content\":null,\"jump\":"+k.getNumberOfSeconds()+"},{\"prefix\":\"D\",\"content\":null,\"jump\":"+k.getNumberOfSeconds()+"}]";
                        JSONArray array = JSONUtil.parseArray(defaultOptionInformation);
                        List<VideoScriptOptionRequestVM> videoScriptOptionRequestVMList = JSONUtil.toList(array, VideoScriptOptionRequestVM.class);
                        videoScriptRequestVM.setOptions(videoScriptOptionRequestVMList);
                        videoScriptRequestVM.setContent(k.getContent());
                    }
                    return videoScriptRequestVM;
                }).collect(Collectors.toList());

                sectionRequestVM.setId(j.getId());
                sectionRequestVM.setName(j.getName());
                sectionRequestVM.setChapterId(j.getChapterId());
                sectionRequestVM.setClassify(j.getClassify());
                sectionRequestVM.setContent(j.getContent());
                sectionRequestVM.setDocumentPath(j.getDocumentPath());
                sectionRequestVM.setRequiredStudyTime(j.getRequiredStudyTime());
                sectionRequestVM.setVideoDuration(j.getVideoDuration());
                sectionRequestVM.setVideoScriptItems(videoScriptRequestVMList);
                return sectionRequestVM;
            }).collect(Collectors.toList());
            chapterRequestVM.setCsSectionList(sectionRequestVMLists);
            return chapterRequestVM;
        }).collect(Collectors.toList());

        CourseRequestVM courseRequestVM = new CourseRequestVM();
        courseRequestVM.setId(id);
        courseRequestVM.setName(csCourse.getName());
        courseRequestVM.setCover(csCourse.getCover());
        courseRequestVM.setLevel(csCourse.getLevel());
        courseRequestVM.setCreateUser(csCourse.getCreateUser());
        courseRequestVM.setIntroduction(csCourse.getIntroduction());
        courseRequestVM.setLecturer(csCourse.getLecturer());
        courseRequestVM.setIntegral(csCourse.getIntegral());
        courseRequestVM.setChapterRequestVMList(chapterRequestVMList);
        courseRequestVM.setPersonInCharge(principalItems);
        courseRequestVM.setSorts(sortsItems);
        courseRequestVM.setSortsName(sortsNames);
        courseRequestVM.setPersonInChargeNames(arrayPrincipalNames);
        return courseRequestVM;
    }

    @Override
    public IPage<CourseItemsVM> getCourseList(Page<CsCourse> page, QueryWrapper<CsCourse> queryWrapper) {
        IPage<CsCourse> csCourseIPage = csCourseMapper.selectPage(page,queryWrapper);
        //将需要的数据赋给课程列表模型
        List<CourseItemsVM> courseItemsVMList = csCourseIPage.getRecords().stream().map(i->{
            CourseItemsVM courseItemsVM = new CourseItemsVM();
            QueryWrapper<CsChapter> csChapterQueryWrapper = new QueryWrapper<>();
            csChapterQueryWrapper.eq("course_id",i.getId());
            List<CsChapter> csChapterList = csChapterMapper.selectList(csChapterQueryWrapper);
            Integer sectionsNum = 0;
            for(CsChapter csChapter : csChapterList){
                QueryWrapper<CsSection> csSectionQueryWrapper = new QueryWrapper<>();
                csSectionQueryWrapper.eq("chapter_id",csChapter.getId());
                sectionsNum += csSectionMapper.selectCount(csSectionQueryWrapper).intValue();
            }
            //解析负责人json
            JSONArray arrayPrincipal = JSONUtil.parseArray(i.getPersonInCharge());
            List<String> principalItems = JSONUtil.toList(arrayPrincipal,String.class);
            //获取负责人名集合
            List<String> arrayPrincipalNames = principalItems.stream().map(j->{
                SysUserDemo sysUserDemo = sysUserDemoMapper.selectById(j);
                return sysUserDemo.getRealname();
            }).collect(Collectors.toList());
            courseItemsVM.setId(i.getId());
            courseItemsVM.setCover(i.getCover());
            courseItemsVM.setSectionNum(sectionsNum);
            courseItemsVM.setLearnOfNum(5); //假数据
            courseItemsVM.setPersonInChargeNames(arrayPrincipalNames);
            courseItemsVM.setCreateTime(i.getCreateTime());
            courseItemsVM.setLevel(i.getLevel());
            courseItemsVM.setName(i.getName());
            return courseItemsVM;
        }).collect(Collectors.toList());
        //将分页数据赋给 IPage<CourseItemsVM>
        IPage<CourseItemsVM> courseItemsVMIPage = new Page<>();
        courseItemsVMIPage.setPages(csCourseIPage.getPages());
        courseItemsVMIPage.setCurrent(csCourseIPage.getCurrent());
        courseItemsVMIPage.setSize(csCourseIPage.getSize());
        courseItemsVMIPage.setTotal(csCourseIPage.getTotal());
        courseItemsVMIPage.setRecords(courseItemsVMList);
        return courseItemsVMIPage;
    }

    @Override
    public Boolean deleteCourse(String id) {
        if(csCourseMapper.deleteById(id)<0){
            return false;
        }
        QueryWrapper<CsChapter> csChapterQueryWrapper = new QueryWrapper<>();
        csChapterQueryWrapper.eq("course_id",id);
        List<CsChapter> csChapterList = csChapterMapper.selectList(csChapterQueryWrapper);
        csChapterList.stream().forEach(i->{
            csChapterMapper.deleteById(i.getId());
            QueryWrapper<CsSection> csSectionQueryWrapper = new QueryWrapper<>();
            csSectionQueryWrapper.eq("chapter_id",i.getId());
            List<CsSection> csSectionList = csSectionMapper.selectList(csSectionQueryWrapper);
            csSectionList.stream().forEach(j->{
                csSectionMapper.deleteById(j.getId());
                if(j.getClassify()==1){
                    QueryWrapper<CsVideoScript> csVideoScriptQueryWrapper = new QueryWrapper<>();
                    csVideoScriptQueryWrapper.eq("section_id",j.getId());
                    List<CsVideoScript> csVideoScriptList = csVideoScriptMapper.selectList(csVideoScriptQueryWrapper);
                    csVideoScriptList.stream().forEach(csVideoScript -> csVideoScriptMapper.deleteById(csVideoScript.getId()));
                }
            });

        });


        return true;
    }

    @Override
    public CourseUserVM getCourseUserVMBYId(String id) {
        //查询课程信息
        CsCourse csCourse = csCourseMapper.selectById(id);

        //通过课程id查询章节信息
        QueryWrapper<CsChapter> chapterQueryWrapper = new QueryWrapper<>();
        chapterQueryWrapper.eq("course_id",id);
        List<CsChapter> csChapterList = csChapterMapper.selectList(chapterQueryWrapper);

        //将章节信息赋值给chapterUserVM
        List<ChapterUserVM> chapterUserVMList = csChapterList.stream().map(chapter->{
            ChapterUserVM chapterUserVM = new ChapterUserVM();
            chapterUserVM.setId(chapter.getId());
            chapterUserVM.setName(chapter.getName());
            //通过每一个章节id查询小节信息并赋值给SectionUserVM模型
            QueryWrapper<CsSection> sectionQueryWrapper = new QueryWrapper<>();
            sectionQueryWrapper.eq("chapter_id",chapter.getId());
            List<CsSection> csSectionList = csSectionMapper.selectList(sectionQueryWrapper);

            List<SectionUserVM> sectionUserVMList = csSectionList.stream().map(section->{
                SectionUserVM sectionUserVM = new SectionUserVM();
                //查找视频脚本信息并赋值
                QueryWrapper<CsVideoScript> videoScriptQueryWrapper = new QueryWrapper<>();
                videoScriptQueryWrapper.eq("section_id",section.getId());
                List<CsVideoScript> csVideoScriptList = csVideoScriptMapper.selectList(videoScriptQueryWrapper);
                List<VideoScriptUserVM> videoScriptUserVMList = csVideoScriptList.stream().map(videoScript->{
                    VideoScriptUserVM videoScriptUserVM = new VideoScriptUserVM();
                    videoScriptUserVM.setId(videoScript.getId());
                    videoScriptUserVM.setNumberOfSeconds(videoScript.getNumberOfSeconds());
                    videoScriptUserVM.setModel(videoScript.getModel());
                    videoScriptUserVM.setContent(videoScript.getContent());
                    videoScriptUserVM.setTitle(videoScript.getTitle());
                    if(videoScript.getModel()==1){
                        JSONArray array = JSONUtil.parseArray(videoScript.getOptionInformation());
                        List<VideoScriptOptionUserVM> videoScriptOptionUserVMList = JSONUtil.toList(array, VideoScriptOptionUserVM.class);
                        videoScriptUserVM.setOptions(videoScriptOptionUserVMList);
                    }else {
                        videoScriptUserVM.setContent(videoScriptUserVM.getContent());
                    }
                    return videoScriptUserVM;
                }).collect(Collectors.toList());

                sectionUserVM.setId(section.getId());
                sectionUserVM.setName(section.getName());
                sectionUserVM.setClassify(section.getClassify());
                sectionUserVM.setContent(section.getContent());
                sectionUserVM.setDocumentPath(section.getDocumentPath());
                sectionUserVM.setRequiredStudyTime(section.getRequiredStudyTime());
                sectionUserVM.setVideoDuration(section.getVideoDuration());
                sectionUserVM.setVideoScriptItems(videoScriptUserVMList);
                return sectionUserVM;
            }).collect(Collectors.toList());

            chapterUserVM.setSectionUserVMItems(sectionUserVMList);
            return chapterUserVM;
        }).collect(Collectors.toList());

        //将课程信息赋值给courseUserVM并返回数据

        CourseUserVM courseUserVM = new CourseUserVM();
        courseUserVM.setCsCourse(csCourse);
        courseUserVM.setChapterUserVMItems(chapterUserVMList);

        return courseUserVM;
    }

    @Override
    public ResponseResult getCourseList() {
        List<CsCourse> courseList = csCourseMapper.selectList(null);
        return ResponseResult.okResult(courseList);

    }
}
